// This file is part of OpenTSDB.
// Copyright (C) 2017 TeleDB Development Group.
//
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 2.1 of the License, or (at your
// option) any later version.  This program is distributed in the hope that it
// will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
// General Public License for more details.  You should have received a copy
// of the GNU Lesser General Public License along with this program.  If not,
// see <http://www.gnu.org/licenses/>.
package net.opentsdb.tsd.service;

import net.opentsdb.core.TSDB;
import net.opentsdb.tsd.HttpQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

/**
 * 重设ttl
 * */
public class ResetTtlService extends RpcServiceImpl{

    private static final Logger LOG = LoggerFactory.getLogger(ResetTtlService.class);

    public ResetTtlService(TSDB tsdb, HttpQuery query){ super(tsdb, query); }

    @Override
    public void doGet() {
        doPost();
    }

    @Override
    public void doPost() {
        Long ttl = Long.valueOf(((Map<String,String>)params).get("ttl"));

        LOG.debug("Successfully remove ttl "+ttl);
        tsdb.getMetaCache().resetTTL(ttl);
        putResponse(true,"change ttl to "+ttl);
    }

    @Override
    public void checks() {
        Map<String,String> map = (Map<String,String>)params;

        if(!map.containsKey("ttl")){
            LOG.info("error reset ttl request");
            putErrorResponse(false,"error delete type request, ex:{ttl:'10'}");
        }
    }
}
